package com.mabang.cxfclient;

import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.wss4j.dom.WSConstants;
import org.apache.wss4j.dom.handler.WSHandlerConstants;

import com.mabang.medata.client.authc.ClientPasswordCallback;

public class ClientMain {
	public static void main(String[] args) {
		JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        org.apache.cxf.endpoint.Client client = factory.createClient("http://localhost:8080/ws/hello?wsdl");
        Endpoint point = client.getEndpoint();  
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        map.put(WSHandlerConstants.USER, "client1");
        map.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
        map.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());
        point.getOutInterceptors().add(new WSS4JOutInterceptor(map));
        try {
			Object[] results = client.invoke("say", "余乙迪");
			System.out.println(results[0]);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}
